import Util from '@/js_sdk/validator/util.js';
	import { getArea ,areaPower} from "@/js_sdk/manage-area/manage.js";
const db = uniCloud.database()
const publicData = {
	items: [
		{value: 1,name: '平台公告',},
		{value: 2,name: '处罚通知',},
		{value: 3,name: '警告通知',},
		{value: 4,name: '活动提醒',}
	],
	target:[
		'指定标签','单独发送'
	],
	towshipData: getArea(),
	searchVal:'',
	imagestyle: {
		"height": 160, // 边框高度
		"width": 160, // 边框宽度
		"border": { // 如果为 Boolean 值，可以控制边框显示与否
			"color": "#eee", // 边框颜色
			"width": "1px", // 边框宽度
			"style": "solid", // 边框样式
		}
	},
}

const publicFun = {
	// 选择平台公告
	radioChange(e) {
		let index =  e.detail.value
		this.formData.type = this.items[index-1]
	},
	// 选择 swiper
	onTarget(index){
		if (this._uid) {
			return
		}
		this.targetIndex = index
		this.formData.targetSend.platform = this.target[index]
	},
	// swiper 2
	onMultipleData(e){
		this.formData.targetSend.label_arr = e.detail.value?e.detail.value:[]
	},
	// swiper3 获取swiper3数据
	getPersonData(push=false){
		let shopField =  "_id,title,logo,address,poiname,area_all"
		let authentcationField = "shop_id,create_uid"
		let shopData = db.collection("shop").field(shopField).getTemp({getOne:false})
		let authenticationData = db.collection("shop_authentication").field(authentcationField).getTemp({getOne:true})
		db.collection(shopData,authenticationData).where(
			{  "_id.shop_authentication": { $size: 1 },
			"area_all.value":db.command.in(areaPower()),
		 }).skip(this.skip).limit(10).get({getOne:false}).then( res =>{
			let data  = res.result.data
			if (push) {
				this.personData.push(...data)
			}else {
				this.personData = data
			}
		})
	},
	// swiper3滚动到底部
	scrollBottom(event){
		this.skip += 10
		this.getPersonData(true)
	},
	// swiper3搜索
	eventSearch(){
		let nameVal = this.searchVal
		// 合并查询条件
		let MergeWhere = {  "_id.shop_authentication": { $size: 1 }, };
		// 构建搜索条件
		let search = {
			$or: [
				/*- 搜索可根据名称进行模糊匹配*/
				{
					'title': {$regex: '.*' + nameVal + '.*',$options: 'i'}
				},{
					'address': {$regex: '.*' + nameVal + '.*',$options: 'i'}
				},{
					'poiname': {$regex: '.*' + nameVal + '.*',$options: 'i'}
				}
			]
		};
		this.where = Object.assign(MergeWhere, search)
		this.getPersonData()
	},
	onBlurEdit(e){
		this.formData.abstract = Util.escapeSpecialCharacters(e.slice(0,80))
	},
}

export {
	publicData,
	publicFun
}